package com.s64.ssm.controller;

import com.s64.ssm.entity.SysUser;
import com.s64.ssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
@CrossOrigin
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping
    public List<SysUser> getAll() {
        return userService.getAll();
    }

    @GetMapping("/del")
    public boolean del(Integer id) {
        return userService.del(id) > 0;
    }

    @GetMapping("/update/{id}")
    public SysUser update(@PathVariable Integer id) {
        return userService.get(id);
    }

    @PostMapping("/update")
    public boolean update(SysUser user) {
        return userService.update(user) > 0;
    }

    @PostMapping("/add")
    public boolean add(SysUser user) {
        return userService.add(user) > 0;
    }
}
